<?php

declare(strict_types=1);

namespace Upside\Router;

final class RouteCollector
{
    /**
     * @var Route[]
     */
    private array $routes = [];

    /**
     * @param class-string $controller
     */
    public function add_route(string $path, string $controller, string $action, string $method, string $name): void
    {
        $this->routes[] = new Route($path, $controller, $action, $method, $name);
    }

    /**
     * @param class-string $controller
     */
    public function get(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'GET', $name);
    }

    /**
     * @param class-string $controller
     */
    public function post(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'POST', $name);
    }

    /**
     * @param class-string $controller
     */
    public function put(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'PUT', $name);
    }

    /**
     * @param class-string $controller
     */
    public function delete(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'DELETE', $name);
    }

    /**
     * @param class-string $controller
     */
    public function patch(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'PATCH', $name);
    }

    /**
     * @param class-string $controller
     */
    public function head(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'HEAD', $name);
    }

    /**
     * @param class-string $controller
     */
    public function options(string $path, string $controller, string $action, string $name): void
    {
        $this->add_route($path, $controller, $action, 'OPTIONS', $name);
    }

    /**
     * @return Route[]
     */
    public function get_routes(): array
    {
        return $this->routes;
    }
}
